<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>订单列表</title>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/js/jquery-easyui-1.4.1/themes/bootstrap/easyui.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/js/jquery-easyui-1.4.1/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/js/jquery-easyui-1.4.1/demo/demo.css">
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-easyui-1.4.1/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
</head>
<body>
	 <div class="easyui-panel" title="筛选" style="width:1100px">
        <div style="padding:5px 30px 5px 30px">
        <form id="ff" method="post">
            <table cellpadding="5">
                <tr>
                	<td>订单编号:</td><td><input type="text" name="orderFormNo" id="orderFormNo"/></td><td><input type="button" value="查询" onclick="search()"/></td>
                </tr>
            </table>
        </form>
        </div>
    </div>
    <table id="orderDg" title="订单列表" style="width:1100px;height:370px" class="easyui-datagrid">
    </table>
    <div id="orderToolbar">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroy()">删除</a>
    </div>
    
    <script type="text/javascript">
    $(function () {
	    //加载信息
	    $('#orderDg').datagrid({
	    	idField:"id",
	        url: 'order_getData.action',
	        loadMsg: '数据装载中......',
	        singleSelect: true,
	        columns: [[
	        { field: 'id', title: '编号', width: 40 },
	        { field: 'orderFormNo', title: '订单编号', width: 100},
	        { field: 'orderFormTotalPrice', title: '订单价格', width: 50 },
	        { field: 'contactName', title: '收货人', width: 50 },
	        { field: 'mobile', title: '收货人电话', width: 70 },
	        { field: 'address', title: '收货地址', width: 100 },
	        { field: 'orderFormRemark', title: '买家备注', width: 100 },
	        { field: 'insertTime', title: '下单时间', width: 60 },
	        { field: 'orderFormPayType', title: '支付方式', width: 50,
	        	formatter: function(value,row,index){
	        		switch (row.orderFormPayType) {
					case 0:
						return "货到付款";
						break;
					case 1:
						return "在线支付";
						break;
					default:
						break;
					}
    			} 
	        },
	        { field: 'orderFormStatus', title: '订单状态', width: 50,
	        	formatter: function(value,row,index){
	        		switch (row.orderFormStatus) {
					case 0:
						return "待支付";
						break;
					case 1:
						return "待发货";
						break;
					case 2:
						return "待收货";
						break;
					case 3:
						return "已完成";
						break;
					case 4:
						return "已评价";
						break;
					case 5:
						return "已取消";
						break;
					case 6:
						return "已退货";
						break;
					default:
						return "";
						break;
					}
    			} 
	        	
	        },
	        { field: '', title: '操作', width: 50,
	        	formatter: function(value,row,index){
	        		switch (row.orderFormStatus) {
					case 1:
						return '<a href="#" onclick="deliver()">发货</a>';
						break;
					default:
						return "无";
						break;
					}
    			} 
	        	
	        }
	        ]],
	        pagination: true,
	        toolbar:'#orderToolbar',
	        fitColumns:true,
	        rownumbers: true
	    });
	});
    
    function search(){
    	$("#orderDg").datagrid("load", {
            "orderFormNo":$("#orderFormNo").val()
        });
    }
    
        function destroy(){
            var row = $('#orderDg').datagrid('getSelected');
            if (row){
                $.messager.confirm('提示','你确定要删除这条记录？',function(r){
                    if (r){
                        $.post('order_delete.action',{id:row.id},function(result){
                            if (result.errorMsg){
                            	$.messager.show({    // show error message
                                    title: 'Error',
                                    msg: result.errorMsg
                                });
                            } else {
                            	$('#orderDg').datagrid('reload');    // reload the user data
                            }
                        },'json');
                    }
                });
            }
        }
        
        function deliver(){
            var row = $('#orderDg').datagrid('getSelected');
            if (row){
                $.messager.confirm('提示','你确定要发货？',function(r){
                    if (r){
                        $.post('order_deliver.action',{id:row.id},function(result){
                            if (result.errorMsg){
                            	$.messager.show({    // show error message
                                    title: 'Error',
                                    msg: result.errorMsg
                                });
                            } else {
                            	$('#orderDg').datagrid('reload');    // reload the user data
                            }
                        },'json');
                    }
                });
            }
        }
    </script>
    <style type="text/css">
        #orderFm{
            margin:0;
            padding:10px 30px;
        }
        .ftitle{
            font-size:14px;
            font-weight:bold;
            padding:5px 0;
            margin-bottom:10px;
            border-bottom:1px solid #ccc;
        }
        .fitem{
            margin-bottom:5px;
        }
        .fitem label{
            display:inline-block;
            width:80px;
        }
        .fitem input{
            width:160px;
        }
    </style>
</body>
</html>